﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Wwtfly.BBS.BackBLL.News;
using Wwtfly.BBS.BackModels.Models.NewsType;
using System.Text;
using Wwtfly.BBS.BackBLL.ExpertNews;
using Wwtfly.BBS.BackModels.Models.ExpertNews;
using Wwtfly.BBS.BackModels.Models.Plays;
using Wwtfly.BBS.BackBLL.Plays;
using Wwtfly.Utility;
using System.Collections;

namespace Wwtfly.BBS.ForeApplication.WebForm
{
    public partial class _default : System.Web.UI.Page
    {
        protected  string newShow1 = "";
        protected  string newShow2 = "";
        protected  string newShow3 = "";
        protected  string newShow4 = "";
        protected string newShow9 = "";
        protected  NewsTypesModel newType5 = null;
        protected  NewsTypesModel newType6 = null;
        protected NewsTypesModel newtype9 = null;
        protected  string LotteryNoList = "";//获取彩种期号信息
        protected  string LotteryCaibi = "";//彩种预测区
        protected  string LotteryNotCaibi = "";//免费预测区
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (!IsPostBack)
                {
                    StringBuilder lotteryWinNumber = new StringBuilder();
                    IList<PlaysShowsModel> playNum = PlaysBLL.GetPlayLotteryWinNumber();

                    if (playNum != null)
                    {    //双色球 七乐彩 3d 大乐透 排列三  七星彩

                        PlaysShowsModel plays5 = playNum.FirstOrDefault(p => p.LotteryID == 5);
                        PlaysShowsModel plays6 = playNum.FirstOrDefault(p => p.LotteryID == 6);
                        PlaysShowsModel plays13 = playNum.FirstOrDefault(p => p.LotteryID == 13);
                        PlaysShowsModel plays39 = playNum.FirstOrDefault(p => p.LotteryID == 39);
                        PlaysShowsModel plays63 = playNum.FirstOrDefault(p => p.LotteryID == 63);
                        PlaysShowsModel plays2 = playNum.FirstOrDefault(p => p.LotteryID == 2);
                 
                                lotteryWinNumber.Append("<li><em>" + plays5.EndTime.ToString("MM-dd") + "&nbsp;<a href=\"LotterySSQ_ZHFB.aspx\">详细</a></em>双色球 " + plays5.PlayNo + "期<br />");
                                lotteryWinNumber.Append(ReBlue(plays5.WinLotteryNumber,plays5.LotteryID));
                                lotteryWinNumber.Append("</li>");

                                lotteryWinNumber.Append("<li><em>" + plays13.EndTime.ToString("MM-dd") + "&nbsp;<a href=\"#\">详细</a></em>七乐彩 " + plays13.PlayNo + "期<br />");
                                lotteryWinNumber.Append(ReBlue(plays13.WinLotteryNumber, plays13.LotteryID));
                                lotteryWinNumber.Append("</li>");


                                lotteryWinNumber.Append("<li><em>" + plays6.EndTime.ToString("MM-dd") + "&nbsp;<a href=\"Lottery3D_ZHFB.aspx\">详细</a></em>福彩3D " + plays6.PlayNo + "期<br />");
                                lotteryWinNumber.Append("<span class=\"red\">" + plays6.WinLotteryNumber + "</span>");
                                lotteryWinNumber.Append("</li>");
                          

                           
                                lotteryWinNumber.Append("<li><em>" + plays39.EndTime.ToString("MM-dd") + "&nbsp;<a href=\"LotteryCJDLT_HMFB.aspx\">详细</a></em>大乐透 " + plays39.PlayNo + "期<br />");
                                lotteryWinNumber.Append(ReBlue(plays39.WinLotteryNumber,plays39.LotteryID));
                                lotteryWinNumber.Append("</li>");
                           
                                lotteryWinNumber.Append("<li><em>" + plays63.EndTime.ToString("MM-dd") + "&nbsp;<a href=\"#\">详细</a></em>排列三 " + plays63.PlayNo + "期<br />");
                                lotteryWinNumber.Append("<span class=\"red\">" + plays63.WinLotteryNumber + "</span>");
                                lotteryWinNumber.Append("</li>");
                          
                                lotteryWinNumber.Append("<li><em>" + plays2.EndTime.ToString("MM-dd") + "&nbsp;<a href=\"#\">详细</a></em>七星彩 " + plays2.PlayNo + "期<br />");
                                lotteryWinNumber.Append("<span class=\"red\">" + plays2.WinLotteryNumber + "</span>");
                                lotteryWinNumber.Append("</li>");
                          
                      
                        LotteryNoList = lotteryWinNumber.ToString();
                    }

                 StringBuilder sbCaibi = new StringBuilder();
                 IList<ExpertNewsShowsModel> expertNews=ExpertNewsBLL.ExpertNewsShowsList(0);
                 if (expertNews != null)
                 {
                     foreach (ExpertNewsShowsModel eptnew in expertNews)
                     {
                         sbCaibi.Append(" <li><em>" + eptnew.CreateTime.ToString("yyyy-MM-dd") + "</em>" + (eptnew.Keyword == "" ? "" : "[" + eptnew.Keyword + "]") + "<a href=\"LookExpertNews.aspx?expertaction=" + eptnew.Id + "\">" + eptnew.Extitle + "</a><span>(" + eptnew.ColourMoney + "彩币)</span></li>");
                     }
                     LotteryCaibi = sbCaibi.ToString();
                 }
                    StringBuilder NotCaibi = new StringBuilder();
                    IList<ExpertNewsShowsModel> expertNews2 = ExpertNewsBLL.ExpertNewsShowsList(1);
                    if (expertNews2 != null)
                    {
                        foreach (ExpertNewsShowsModel eptnew in expertNews2)
                        {
                            NotCaibi.Append(" <li><em>" + eptnew.CreateTime.ToString("yyyy-MM-dd") + "</em>" + (eptnew.Keyword == "" ? "" : "[" + eptnew.Keyword + "]") + "<a href=\"LookExpertNews.aspx?expertaction=" + eptnew.Id + "\" >" + eptnew.Extitle + "</a></li>");
                        }
                        LotteryNotCaibi = NotCaibi.ToString();
                    }
                    NewsTypesModel newType1 = NewTypesBLL.GetInfo(1);
                    newShow1= ContentHtml(NewList(6, newType1.Id),newType1.Title);
                  

                    NewsTypesModel newType2 = NewTypesBLL.GetInfo(2);
                    newShow2 = ContentHtml(NewList(6, newType2.Id), newType2.Title);

                    NewsTypesModel newType3 = NewTypesBLL.GetInfo(3);
                    newShow3 = ContentHtml(NewList(6, newType3.Id), newType3.Title);

                    NewsTypesModel newType4 = NewTypesBLL.GetInfo(4);
                    newShow4= ContentHtml(NewList(6, newType4.Id), newType4.Title);

                    newType5 = NewTypesBLL.GetInfo(5);
                    this.Repeater5.DataSource = NewList(10, newType5.Id);
                    this.Repeater5.DataBind();

                    newType6 = NewTypesBLL.GetInfo(6);
                    this.Repeater6.DataSource = NewList(10, newType6.Id);
                    this.Repeater6.DataBind();
                    newtype9 = NewTypesBLL.GetInfo(9);
                    newShow9 = ContentHtml9(NewsBLL.NewsConetList(5, newtype9.Id));

                }
            }
        }
      
        protected string ContentHtml9(DataTable newdt)
        {
            StringBuilder sb = new StringBuilder();
            if (newdt.Rows.Count > 0)
            {
                int r = newdt.Rows.Count;
                if (r <= 2)
                {
                    for (int i = 0; i < r; i++)
                    {
                        if (i < 2)
                        {
                            sb.Append(" <div class=\"h_tj clearfix\"><dl><dt><a href=\"NewShows.aspx?newactionId=" + newdt.Rows[i]["Id"] + "\">" + newdt.Rows[i]["NewsTitle"] + "</a></dt>");
                            sb.Append("<dd>");
                            sb.Append(ContentHelper.Substring( newdt.Rows[i]["NewsContent"].ToString(),150,"...",1));
                            sb.Append("&nbsp;[<a  href=\"NewShows.aspx?newactionId=" + newdt.Rows[i]["Id"] + "\" target=\"_blank\">详细</a>]");
                            sb.Append("</dd>");
                            sb.Append("</dl> </div>");
                        }
                    }
                    sb.Append("<ul class=\"h_tj_ul\">");
                    sb.Append("</ul>");
                }
                else
                {
                    for (int i = 0; i < 2; i++)
                    {
                           sb.Append(" <div class=\"h_tj clearfix\"><dl><dt><a href=\"NewShows.aspx?newactionId=" + newdt.Rows[i]["Id"] + "\">" + newdt.Rows[i]["NewsTitle"] + "</a></dt>");
                            sb.Append("<dd>");
                            sb.Append(ContentHelper.Substring(newdt.Rows[i]["NewsContent"].ToString(), 150, "...", 1));
                            sb.Append("&nbsp;[<a  href=\"NewShows.aspx?newactionId=" + newdt.Rows[i]["Id"] + "\" target=\"_blank\">详细</a>]");
                            sb.Append("</dd>");
                            sb.Append("</dd>");
                            sb.Append("</dl> </div>");
                    }
                    sb.Append("<ul class=\"h_tj_ul\">");
                    for (int j = 2; j < r; j++)
                    {
                        sb.Append("<li>[" + newdt.Rows[j]["Keyword"] + "] <a href=\"NewShows.aspx?newactionId=" + newdt.Rows[j]["Id"] + "\">" + newdt.Rows[j]["NewsTitle"] + "</a></li>");
                    }
                    sb.Append("</ul>");
                }
                
            }

            return sb.ToString();
        }
        protected  string ContentHtml(DataTable newdt,string typeTitle)
        {
            StringBuilder sb = new StringBuilder();
            if (newdt.Rows.Count > 0)
            {
                
                for (int i = 0; i < newdt.Rows.Count; i++)
                {
                    if (i == 0)
                    {
                        sb.Append(" <h1>" + typeTitle + "<a href=\"NewShows.aspx?newactionId=" + newdt.Rows[i]["Id"] + "\"><span class=\"red  P2Left\"> " + newdt.Rows[i]["NewsTitle"].ToString() + "</span></a></h1>");

                    }
                    else
                    {
                        sb.Append(" <li> <em>["+newdt.Rows[i]["Keyword"]+"]</em><a href=\"NewShows.aspx?newactionId="+newdt.Rows[i]["Id"]+"\">"+newdt.Rows[i]["NewsTitle"].ToString()+" </a></li> ");
                    }
                }
            }
            return sb.ToString();

        }
        protected static string ReBlue(string win,int lottery)
        {
            if (win == "")
            {
                return "";
            }
           StringBuilder sbstr =new StringBuilder();
          string[] winstr=win.Split('+');
          if (winstr.Length == 2)
          {
              if (lottery == 5 || lottery == 39 || lottery == 13)
              {
                  sbstr.Append("<span class=\"red\">" + winstr[0] + "</span>");
                  sbstr.Append("<span class=\"blue\">" + winstr[1] + "</span>");
              }
              
          }
          return sbstr.ToString();
        }
        /// <summary>
        /// 根据新闻类型ID获取最新新闻信息
        /// </summary>
        /// <param name="typeid"></param>
        /// <returns></returns>
        protected  DataTable NewList(int sum,int typeid)
        {
            return NewsBLL.NewsList(sum, typeid);
        }


        protected static string Timestr(string timestr)
        {
            DateTime time = DateTime.Parse(timestr);
            return time.ToString("yyyy-MM-dd");
        }
    }
}